#!/bin/sh

# 加载工具类
. /etc/idnewnil/utils.sh

# 配置动态dns
CF_KEY=$(getstr '.cf_key')
uci set ddns.myddns_ipv4.service_name='cloudflare.com-v4'
if [ ${CF_KEY} ]; then
    uci set ddns.myddns_ipv4.enabled='1'
fi
uci set ddns.myddns_ipv4.use_ipv6='0'
uci set ddns.myddns_ipv4.lookup_host=$(getstr '.["domain.home"]')
uci set ddns.myddns_ipv4.domain=$(getstr '.["domain.@home"]')
uci set ddns.myddns_ipv4.username=$(getstr '.email')
uci set ddns.myddns_ipv4.password=${CF_KEY}
uci set ddns.myddns_ipv4.ip_source='network'
uci set ddns.myddns_ipv4.ip_network='wan'
uci set ddns.myddns_ipv4.interface='wan'
uci set ddns.myddns_ipv4.use_syslog='2'
uci set ddns.myddns_ipv4.check_unit='minutes'
uci set ddns.myddns_ipv4.force_unit='minutes'
uci set ddns.myddns_ipv4.retry_unit='seconds'
uci del ddns.global.upd_privateip
uci set ddns.global.ddns_rundir='/var/run/ddns'
uci set ddns.global.ddns_logdir='/var/log/ddns'
uci set ddns.myddns_ipv6.enabled='0'
uci commit ddns
/etc/init.d/ddns restart
